package org.dtrd.modules.device.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dtrd.modules.device.entity.bean.DevicePushContentDetail;
import org.dtrd.modules.device.entity.po.DtrdEntRdDevicePushContent;
import org.dtrd.modules.device.mapper.DtrdEntRdDevicePushContentMapper;
import org.dtrd.modules.device.service.IDtrdEntRdDevicePushContentService;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 智能设备推送记录 服务实现类
 * </p>
 *
 * @author xiao
 * @since 2022-01-12
 */
@DS("multi-datasource1")
@Service
public class DtrdEntRdDevicePushContentServiceImpl extends ServiceImpl<DtrdEntRdDevicePushContentMapper, DtrdEntRdDevicePushContent> implements IDtrdEntRdDevicePushContentService {

    @Override
    public boolean saveOrUpdateDevicePushContent(DevicePushContentDetail dto) {
        DtrdEntRdDevicePushContent dtrdEntRdDevicePushContent = new DtrdEntRdDevicePushContent();
        if (dto.getDataId() == null) {
            dtrdEntRdDevicePushContent = dtrdEntRdDevicePushContent.init();
        }
        dtrdEntRdDevicePushContent.parseFromDto(dto);
        return saveOrUpdate(dtrdEntRdDevicePushContent);
    }

    @Override
    public void saveOrUpdateDevicePushContent(String signature ,String sn, String content, int brand,int category) {
        DtrdEntRdDevicePushContent po = new DtrdEntRdDevicePushContent().init();
        po.setPushContent(content);
        po.setMsgId(signature);
        po.setDeviceBrand(brand);
        po.setDeviceSn(sn);
        po.setDeviceCategory(category);
        saveOrUpdate(po);
    }

    @Override
    public DtrdEntRdDevicePushContent getPushRecordByMsgId(String signature) {
        return baseMapper.getPushRecordByMsgId(signature);
    }

}
